﻿using System;
using System.Collections.Generic;
using System.Text;

using ET;

namespace Marx
{

    [ObjectSystem]
    public class GlobalTimerAwakeSystem : AwakeSystem<GlobalTimer>
    {
        public override void Awake(GlobalTimer self)
        {
            self.Awake();
        }
    }

    [ObjectSystem]
    public class GlobalTimerUpdateSystem : UpdateSystem<GlobalTimer>
    {
        public override void Update(GlobalTimer self)
        {
            self.Update();
        }
    }

    public class GlobalTimer : Entity, IUpdate, IAwake
    {
        public static GlobalTimer Instance { get; private set; }

        private TimerSystem timer_;

        public void Awake()
        {
            Instance = this;
            timer_ = new TimerSystem();
        }

        public void Update()
        {
            timer_.Update();
        }

        public int CreateTimer(Action<int> callback, long delay, long interval = long.MaxValue)
        {
            return timer_.CreateTimer(callback, delay, interval);
        }

        public void RemoveTimer(int id)
        {
            timer_.RemoveTimer(id);
        }

        public void Clear()
        {
            timer_.Clear();
        }
    }
}
